package org.framework.core.orm.support.factory;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import org.framework.core.orm.IPage;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

@Component
public class PageFactory implements FactoryBean<IPage> {
	Properties dataSource = new Properties();
	PageDialect dialect;
	
	public PageFactory() {
		try {
			dataSource.load(new FileInputStream(new File((PageFactory.class.getResource("/")+"config/system/hibernate.properties").substring(6))));
			dialect = PageDialect.dialectOf(dataSource.getProperty("dataSource.dialect"));
			
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	@Override
	public IPage getObject() throws Exception {
		 
		return dialect.getiPage();
	}

	@Override
	public Class<?> getObjectType() {
		
		return dialect.getiPageClass();
	}

	@Override
	public boolean isSingleton() {
		
		return true;
	}

}
